package com.steak.transaction.service;

import com.steak.transaction.datasource.DatasourceScope;
import com.steak.transaction.result.R;
import lombok.AllArgsConstructor;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

/**
 * @author 刘牌
 * @Title:
 * @date 2022/3/19:59
 */
@Service
@AllArgsConstructor
public class IntegralService {

    private final JdbcTemplate jdbcTemplate;

    @DatasourceScope(scope = "master")
    public R increaseIntegral(Integer userId , Integer integral){
        String sql = "UPDATE integral SET integral = ( SELECT inters.integral FROM ( SELECT ( inte.integral + "+integral+" ) integral FROM integral inte WHERE inte.user_id = "+userId+" ) inters) WHERE user_id = "+userId+"";
        jdbcTemplate.update(sql);
        return R.builder().code(200).msg("increase integral success").build();
    }
}
